This sample is a very simple web (HTTP) server that demonstrates how to exploit the single-link multi-homing feature of OT 1.3.
About Single-Link Multi-Homing
Open Transport 1.3 introduces single-link multi-homing, a mechanism by which Open Transport can support multiple different IP addresses on the same hardware interface. This is useful for users, like Internet service providers (ISPs), that want to give each of their clients a distinct IP address, without requiring separate computers for each address.
This ability is transparent to OT clients that are not specifically interested in it. When writing a server, you should bind to the IP address kOTAnyInetAddress and OT will pass along connections attempts for any IP address on the machine.
However, sometimes it is useful for you to distinguish between the various IP addresss. For example, a web server might want to offer the option of serving different web pages for different IP address.
User Level Operation
Before using the sample, make sure you have OT 1.3 installed. This code relies on features of OT 1.3 and, while it will operate under earlier versions of OT, it won’t actually demonstrate anything useful.
First up, configure your machine with multiple IP address as per <<<where is this described for user-level operation???>>>. To assist you in setting up multiple IP addresses, the sample includes a sample “IP Secondary Addresses”. Just edit that sample file, rename it to “IP Secondary Addresses” (without the quotes) and put it in your Preferences folder. The next time TCP/IP loads, it will enable the secondary addresses. [You should most probably restart to force TCP/IP to reload.]
In this example, I’ll assume your machine has a primary IP address 1.2.3.4 and a secondary address 1.2.3.5.
After setting up your secondary addresses, you should run the sample. This will create a folder (in the same folder as the application) for each IP address on the machine. In this example, the folders will be called “1.2.3.4” and “1.2.3.5”.
Now move your HTML source into the folders. Your root HTML file should be called “index.html”. Edit your HTML source so that you can recognise which IP address it was vended from.
[There is a sample HTML source tree in the folder “Sample HTTP Source” included in the distribution. You can duplicate the contents of this folder into your various IP address folders and edit it there. The sample “index.html” document even has a place for you to insert the appropriate IP address.]
Now connect to your server using a web browser. Note that if you connect to address “http://1.2.3.4”, you will get the HTML from the “1.2.3.4” folder, and if you connect to address “http://1.2.3.5”, you will get the HTML from the “1.2.3.5” folder.
Building the Sample
This sample builds with Metrowerks CodeWarrior 11 and the OT 1.3 interfaces and libraries. To build the sample, first open each project and set the “PreReleaseInterfaces” and “PreReleaseLibraries” access paths to point to your Open Transport interfaces and libraries. Then choose Make from the Project menu.
Once you have set the access paths, you can use the “Metrowerks Build Script” to rebuild the projects automatically.
Packing List
Read Me About Simple Server — This document.
OTSimpleServer-PPC.µ — A PPC project to build the sample.
OTSimpleServer-PPC — A compiled version of the PPC project.
OTSimpleServer-68K.µ — A 68K project to build the sample.
OTSimpleServer-68K — A compiled version of the 68K project.
OTSimpleServerHTTPTest.c — Source to the main line of the project, a wrapper that decides what IP addresses are on the machine, and calls the OTSimpleServerHTTP module to start an HTTP server for each.
OTSimpleServerHTTP.h — Interface to the following.
OTSimpleServerHTTP.c — A semi-independent module that implements an HTTP server than runs in a thread.
Sample “IP Secondary Addresses” — A sample “IP Secondary Addresses” file, which you can edit for your environment.
Sample HTTP Source — A folder containing a sample HTTP source tree for your testing purposes.
Metrowerks Build Script — An AppleScript for rebuilding both projects.
Restrictions and Caveats
This sample was designed to illustrate the use of single-link multi-homing as simply as possible, not for speed. It uses OT in synchronous/blocking mode, with Thread Manager threads, and kOTSyncIdleEvents to simplify the code design. As such, it is unlikely to be a very fast web server. If you decide that my approach is not fast enough, check out the OTVirtualServer sample, which demonstrates techniques for writing a very fast server using OT.
The code also does not implement a very full-featured web server. It basically listens for simple GET commands on port 80, and responds with the contents of the corresponding file. The server has a number of limitations:
• It does not deal with mapping HTTP paths to Mac OS paths (eg a/b to :a:b).
• It use a hardwired mapping of extensions to MIME types. A real server would use Internet Config to get this information.
• It does not deal with any complicated HTTP requests.
The rule here is that it only implements what’s needed to support simple web browsing in order to demonstrate OT’s single-link multi-homing.
Lastly, the server is NOT SECURE!!! Do not use this as a basis for a production web server without evaluating the security considerations.
Credits and Version History
If you find any problems with this sample, mail <DevSupport@apple.com> with “Attn: Quinn” as the first line of your mail and I’ll try to fix them up.
Version 1.0d1 was the version demonstrated on stage at WWDC. It used hardwired IP addresses because the OTInetGetSecondaryAddresses was not ready in time.
Version 1.2d1 is the first widely distributed version, released in conjunction with Open Transport 1.3.